package com.hbt.myplus.controller;

import com.hbt.myplus.model.Section;
import com.hbt.myplus.service.impl.SectionServiceImpl;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.hbt.myplus.service.ISubjectService;
import com.hbt.myplus.service.impl.SubjectServiceImpl;
import com.hbt.myplus.model.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hbt.myplus.utils.ResponseWeb;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
    * 医科 前端控制器
    * </p>
 *
 * @author astupidcoder
 * @since 2020-12-26
 * @version v1.0
 */
@RestController
@RequestMapping("subject")


public class SubjectController {

    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private SubjectServiceImpl subjectService;

    @Autowired
    private SectionServiceImpl sectionService;
    /**
     * 查询分页数据
     */
    @GetMapping(value = "/s")
    public ResponseWeb<Page> findListByPage(@RequestParam(name = "pageNum", defaultValue = "1") int pageNum,@RequestParam(name = "pageSize", defaultValue = "20") int pageSize){


        return null;
    }

    @GetMapping(value = "/all")
    public ResponseWeb getAll(){
        List<Subject> subjectList = subjectService.list();
        List<Section> sectionList = sectionService.list();
        for (Subject subject: subjectList) {
            subject.setSections(sectionList.stream().filter(a -> a.getSubjectId().equals(subject.getId())).collect(Collectors.toList()));
        }

        return new ResponseWeb(subjectList);
    }


    /**
     * 根据id查询
     */
    @GetMapping(value = "/{id}")
    public ResponseWeb<Subject> getById(@PathVariable("id") String id){
       return null;
    }

    /**
     * 新增
     */
    @PostMapping
    public ResponseWeb<Subject> add(@RequestBody Subject subject){
        return null;
    }

    /**
     * 删除
     */
    @DeleteMapping
    public ResponseWeb<String> delete(@RequestParam("ids") List<String> ids){
        return null;
    }

    /**
     * 修改
     */
    @PutMapping
    public ResponseWeb<Subject> update(@RequestBody Subject subject){
        return null;
     }

}
